package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据userId+dishId+dishFlavor查询购物车
     * @param shoppingCart
     * @return
     */
    ShoppingCart selectBy(ShoppingCart shoppingCart);

    // 新增购物车
    @Insert("insert into shopping_cart (user_id, dish_id, setmeal_id, dish_flavor, name, image, amount, number, create_time) " +
    "values (#{userId},#{dishId},#{setmealId},#{dishFlavor},#{name},#{image},#{amount},#{number},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    // 修改购物车的数量
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumber(ShoppingCart cart);

    // 查询用户的购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    // 清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void delete(Long userId);

    // 根据userId+dishId/setmealId+dishFlavor，查询购物车
    ShoppingCart selectByCart(ShoppingCart cart);

    // 更加id删除购物车
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    // 批量插入购物车
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
